// pages/item/item.js
const http = require("../../utils/http");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true, //轮播是否有小圆点
    vertical: false, //false 横向   true 纵向
    autoplay: true, //自动播放
    interval: 2000, //动画时间
    duration: 500, //间隔时间
    circular: true, //衔接动画
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    itemObj: {},
    seasonArr: [],
    productType: [],
    xiangqing: {},
    msg_swiperArr: [],
    gaiyaotype: true,
    xiangxitype: false,
    jiagetype: false,
    gaiyaoTop: 0, //概要离顶部的距离
    xiangxiTop: 0,
    jiageTop: 0,
    type: false //false  tabbar不显示； true tabbar显示

  },
  btnCel() {
    wx.makePhoneCall({
      phoneNumber: '13637589645' //仅为示例，并非真实的电话号码
    })
  },
  //返回首页
  goHome() {
    wx.navigateBack();
  },
  // 标题跳转
  topTitle(e) {
    console.log(e);
    let id = e.target.dataset.id;
    wx.pageScrollTo({
      selector: '#' + id,
      duration: 300
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取内容页数据
    http.request("product/product/getProductDetails/" + options.id, "", "get").then(res => {
      this.setData({
        itemObj: res.data,
        seasonArr: res.data.product_base_info.product_season,
        productType: res.data.product_base_info.product_type,
        xiangqing: res.data.product_base_info,
      });
      console.log(res.data.product_details_info.product_trip_details[0].product_trip_poi_pic);
    }).then(() => {
      //获取某个 view离顶部的距离的
      wx.createSelectorQuery().select("#gaiyao").boundingClientRect(rect => {
        this.setData({
          gaiyaoTop: rect.top
        })
      }).exec();
      wx.createSelectorQuery().select("#xiangxi").boundingClientRect(rect => {
        this.setData({
          xiangxiTop: rect.top
        })
      }).exec();
      wx.createSelectorQuery().select("#jiage").boundingClientRect(rect => {
        this.setData({
          jiageTop: rect.top
        })
      }).exec();
    })
  },

  //页面滚动时触发的钩子
  onPageScroll(ev) {
    const top = ev.scrollTop + 10;
    if (top >= this.data.gaiyaoTop) {
      this.setData({
        type: true
      })
    } else {
      this.setData({
        type: false
      })
    }
    const {
      gaiyaoTop,
      xiangxiTop,
      jiageTop,
      gaiyaotype,
      xiangxitype,
      jiagetype
    } = this.data;
    //滚动时需要切换 激活状态的tabbar
    if (top >= gaiyaoTop && top < xiangxiTop) {
      this.setData({
        gaiyaotype: true,
        xiangxitype: false,
        jiagetype: false
      })
    } else if (top < jiageTop) {
      this.setData({
        gaiyaotype: false,
        xiangxitype: true,
        jiagetype: false
      })
    } else {
      this.setData({
        gaiyaotype: false,
        xiangxitype: false,
        jiagetype: true
      })
    }
  }
})